<?php


namespace app\libs\exception;


use app\facade\ExceptionCode;
use think\Exception;

class BaseException extends Exception
{
    public $code = 500;
    public $message = "对不起, 服务器内部异常(*￣︶￣)!";
    public $statusCode = 99999;

    /**
     * @throws ParamException
     */
    public function __construct($statusCode = "", $code = "", $message = "")
    {
        $this->judgeCode($statusCode, $code, $message);

    }

    /**
     * @throws ParamException
     */
    private function judgeCode($statusCode, $code, $message): void
    {
        $this->message = ExceptionCode::issueMessage($this->statusCode);

        if ($statusCode != "") {
            $this->statusCode = $statusCode;
        }

        if ($code != "") {
            $this->code = $code;
        }

        if ($message != "") {
            $this->message = $message;
        }

        if ($code == "" || $statusCode == "") {
            return;
        }

        if (!is_numeric($statusCode) || !is_numeric($code)) {
            throw new ParamException(10004);
        }
    }
}